﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using NetCoreCMS.IServices;

namespace NetCoreCMS.Web.Areas.WebApi.Controllers
{
    public class Get_ArticleController : UserController
    {
        public IArticleService _article { get; set; }
        public IFavoriteService _favorite { get; set; }
        [HttpGet]
        public IActionResult Get(int id)
        {
            var sys = Common.XMLConfig.Sysconfig.loadConfig(_env.ContentRootPath);
            var model = _article.GetModel(id);
            model.img_url = sys.weburl + model.img_url;
            if(model.albums!=null)
            {
                for (int i = 0; i < model.albums.Count; i++)
                {
                    model.albums[i].original_path = sys.weburl + model.albums[i].original_path;
                    model.albums[i].thumb_path = sys.weburl + model.albums[i].thumb_path;
                }
            }
            int shoucang = 0;
            try
            {
                var user = GetUserInfo();
                if (user != null)
                {
                    var list = _favorite.GetList(1, 1000, "where user_id=" + user.id, "id desc");
                    if(list.Where(a=>a.like_id==id&&a.ftype==2).Count()>0)
                    {
                        shoucang = 1;
                    }
                }
            }
            catch (Exception)
            {

            }
            return Ok(new { status = 1, data = model,shoucang=shoucang});
        }
    }
}